#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<string.h>
struct stu
{
	char name[20];
	int age;
	int toil;
 };
swap(const void* e1, const void* e2, size_t seo)
{
	int i;
	for ( i = 0; i < seo; i++)
	{
		
		char c = *((char*)e1+i);
		*((char*)e1 + i) = *((char*)e2+i);
		*((char*)e2+i) = c;
	}

}
int com_int(const void* e1, const void* e2)
{
	return *(int*)e1 - *(int*)e2;
}

int com_char(const void* e1, const void* e2)
{
	if (*(char*)e1 > *(char*)e2)
	{
		return 1;
	}
	return -1;
}
int com_stu(const void* e1, const void* e2)
{
	if (((struct stu*)e1)->toil > ((struct stu*)e2)->toil)
	{
		return 1;
	}
	return -1;
}
paixu(void* arr, size_t se, size_t seo, int (*com)(const void* e1, const void* e2))
{
	for (int i = 0; i < se - 1; i++)
	{
		for (int j = 0; j < se - 1 - i; j++)
		{
			if (com_stu((char*)arr + j * seo, (char*)arr + (j + 1) * seo)>0)
			{
				swap((char*)arr + j * seo, (char*)arr + (j + 1) * seo, seo);
			}
		}
	}
}
void dayin(char * arr,size_t se, size_t seo)
{
	for (int i = 0; i < se; i++)
	{
		printf("%c ", *(arr + i));
	}
}

void test1()
{
	int arr[10] = { 0 };
	int i = 0;
	while (scanf("%d", &arr[i]) != -1)
	{
		i++;
	}
	size_t se = sizeof(arr) / sizeof(arr[0]);
	size_t seo = sizeof(arr[0]);
	paixu(arr, se, seo, com_int);
	dayin(arr, se, seo);
}
void test2()
{
	char arr[10] = "cbdnhafjk";
	size_t se = sizeof(arr) / sizeof(arr[0]);
	size_t seo = sizeof(arr[0]);
	paixu(arr, se, seo, com_char);
	dayin(arr, se, seo);
}
void dayin3(struct stu* arr, size_t se, size_t seo)
{
	for (int i = 0; i < se; i++)
	{
		printf("%s ", (arr + i)->name);
		printf("%d ", (arr+i)->age);
		printf("%d ", (arr + i)->toil);
		printf("\n");
	}
}
void test3()
{
	struct stu arr[3] = { {"zhangsan",16,178},{"lisi",20,168},{"wangwu",30,150} };
	size_t se = sizeof(arr) / sizeof(arr[0]);
	size_t seo = sizeof(arr[0]);
	dayin3(arr, se, seo);

	paixu(arr, se, seo, com_stu);
	dayin3(arr, se, seo);

}
int main()
{
	//test1();
	//test2();
	test3();
	return 0;
}